









<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>iBaGuice - Data Source</title>
    <link rel="stylesheet" href="./css/maven-theme.css" type="text/css" />
    <link rel="stylesheet" href="./css/maven-base.css" type="text/css"/>
    <link rel="stylesheet" href="./css/prettify.css" type="text/css"/>
    <link rel="stylesheet" href="./css/print.css" type="text/css" media="print" />
    <script type="text/javascript" src="./js/prettify.js"></script>
    <script type="text/javascript" src="./js/niftycube.js"></script>
    <script type="text/javascript">
        window.onload=function() {
            Nifty("div\#wrapper", "big");
            Nifty("div#breadcrumbs", "small");
            Nifty("div\#navcolumn", "small");
            Nifty("div.source", "medium");
            prettyPrint();
        }
    </script>
          <meta name="author" content="The iBaGuice Team" />
          </head>
  <body>
    <div id="wrapper">
        <div id="banner">
                      <a href="http://ibaguice.googlecode.com/svn/site/1.0-beta-1/index.html" id="bannerLeft"  >
    
                                            <img src="images/logo.png" alt="iBaGuice: enjoy the power of iBatis + Google Guice" />
    
            </a>
                            <div class="clear">
            <hr/>
          </div>
        </div>
        <div id="breadcrumbs">
              
  

  
    
            
  
    
            <div class="xleft">
        <span id="publishDate">Last Published: 2010-02-10</span>
                  &nbsp;| <span id="projectVersion">Version: 1.0-beta-1</span>
                      </div>
                <div class="xright">      
  

  
    
            
  
    
  </div>
          <div class="clear">
            <hr/>
          </div>
        </div>
        <div id="leftColumn">
          <div id="navcolumn">
               
  

  
    
            
  
    
                       <h5>iBaGuice - Main</h5>
            <ul>
              
    <li class="none">
                    <a href="index.html">Introduction</a>
          </li>
              
    <li class="none">
                    <a href="core.html">The Core components</a>
          </li>
              
    <li class="none">
                    <a href="dao.html">The DAO Module</a>
          </li>
          </ul>
              <h5>Data Sources</h5>
            <ul>
              
    <li class="none">
                    <a href="datasource.html#Unpooled_Data_Source_Provider">Unpooled Data Source Provider</a>
          </li>
              
    <li class="none">
                    <a href="datasource.html#Pooled_Data_Source_Provider">Pooled Data Source Provider</a>
          </li>
              
    <li class="none">
                    <a href="datasource.html#JNDI_Data_Source_Provider">JNDI Data Source Provider</a>
          </li>
              
    <li class="none">
                    <a href="datasource.html#Basic_Data_Source_Provider">Basic Data Source Provider</a>
          </li>
              
    <li class="none">
                    <a href="datasource.html#Shared_Pool_Data_Source">Shared Pool Data Source</a>
          </li>
              
    <li class="none">
                    <a href="datasource.html#Per_User_Pool_DataSource">Per User Pool DataSource</a>
          </li>
              
    <li class="none">
                    <a href="datasource.html#Connection_Pool_Data_Source_driver_adapter">Connection Pool Data Source driver adapter</a>
          </li>
              
    <li class="none">
                    <a href="datasource.html#C3P0_Provider">C3P0 Provider</a>
          </li>
          </ul>
              <h5>Caching support</h5>
            <ul>
              
    <li class="none">
                    <a href="caching.html#Ehcache">Ehcache</a>
          </li>
              
    <li class="none">
                    <a href="caching.html#Hazelcast">Hazelcast</a>
          </li>
              
    <li class="none">
                    <a href="caching.html#JBoss_Cache">JBoss Cache</a>
          </li>
              
    <li class="none">
                    <a href="caching.html#Memcached">Memcached</a>
          </li>
              
    <li class="none">
                    <a href="caching.html#OSCache">OSCache</a>
          </li>
          </ul>
              <h5>Miscellaneous</h5>
            <ul>
              
    <li class="none">
                    <a href="stats.html">Project stats</a>
          </li>
              
    <li class="none">
                    <a href="iBaGuice-1.0-beta-1.pdf">PDF Manual</a>
          </li>
          </ul>
              <h5>Project Documentation</h5>
            <ul>
              
                
                    
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
              
        <li class="collapsed">
                    <a href="project-info.html">Project Information</a>
                </li>
              
                
                    
                  
                  
                  
              
        <li class="collapsed">
                    <a href="project-reports.html">Project Reports</a>
                </li>
          </ul>
              <h5>Modules</h5>
            <ul>
              
    <li class="none">
                    <a href="ibaguice-core/index.html">Core</a>
          </li>
              
    <li class="none">
                    <a href="ibaguice-dao/index.html">DAO</a>
          </li>
              
    <li class="none">
                    <a href="ibaguice-c3p0/index.html">c3p0</a>
          </li>
              
    <li class="none">
                    <a href="ibaguice-dbcp/index.html">Apache DBCP</a>
          </li>
              
    <li class="none">
                    <a href="ibaguice-oscache/index.html">OSCache</a>
          </li>
              
    <li class="none">
                    <a href="ibaguice-memcached/index.html">Memcached</a>
          </li>
              
    <li class="none">
                    <a href="ibaguice-ehcache/index.html">Ehcache</a>
          </li>
              
    <li class="none">
                    <a href="ibaguice-jbosscache/index.html">JBoss Cache</a>
          </li>
              
    <li class="none">
                    <a href="ibaguice-hazelcast/index.html">Hazelcast Cache</a>
          </li>
              
    <li class="none">
                    <a href="ibaguice-samples/index.html">Samples</a>
          </li>
          </ul>
              <h5>External Links</h5>
            <ul>
              
    <li class="none">
                    <a href="">Project Page</a>
          </li>
              
    <li class="none">
                    <a href="http://ibatis.apache.org/" class="externalLink">iBatis</a>
          </li>
              
    <li class="none">
                    <a href="../google-guice/">Google Guice</a>
          </li>
          </ul>
                                               <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
            <img class="poweredBy"
                 alt="Built by Maven"
                 src="./images/logos/maven-feather.png"
                 width="90"
                 height="30"
                 border="1" />
          </a>
                           
  

  
    
            
  
    
            </div>
        </div>
        <div id="bodyColumn">
          <div id="contentBox">
            <div class="section"><h2>DataSource setup</h2>
<p>The <tt>com.google.code.ibaguice.core.datasource</tt> package of <i>ibaguice-core</i> module comes with an easy-to-use set of classes that makes easier the built-in <i>iBatis</i> <tt>javax.sql.DataSource</tt> creation using Guice, through configurable Data Source Providers.</p>
<p><i>Configurable</i> means that users are free to bind <tt>com.google.inject.name.Named</tt> properties and let Guice injects them.</p>
<p>Moreover we added, in separated modules, the support for the popular:</p>
<ul><li>Apache <a href="http://commons.apache.org/dbcp" class="externalLink">DBCP</a>;<p>and</p>
</li>
<li><a href="http://www.mchange.com/projects/c3p0/index.html" class="externalLink">C3P0</a>.</li>
</ul>
<div class="section"><h3><a name="Unpooled_Data_Source_Provider">Unpooled Data Source Provider</a></h3>
<p>The <tt>com.google.code.ibaguice.core.datasource.UnpooledDataSourceProvider</tt> is the provider that builds the <tt>org.apache.ibatis.datasource.unpooled.UnpooledDataSource</tt> and helps users to configure it.</p>
<p>Follows below the resume table of supported properties:</p>
<table class="bodyTable"><tbody><tr class="a"><th align="left">Property</th>
<th align="center">Required</th>
<th align="center">Bind Java Type</th>
</tr>
<tr class="b"><td align="left">JDBC.driver</td>
<td align="center">true</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="a"><td align="left">JDBC.url</td>
<td align="center">true</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="b"><td align="left">JDBC.username</td>
<td align="center">true</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="a"><td align="left">JDBC.password</td>
<td align="center">true</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="b"><td align="left">JDBC.autoCommit</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="a"><td align="left">JDBC.loginTimeout</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">JDBC.driverProperties</td>
<td align="center">false</td>
<td align="center">java.util.Properties</td>
</tr>
</tbody>
</table>
</div>
<div class="section"><h3><a name="Pooled_Data_Source_Provider">Pooled Data Source Provider</a></h3>
<p>The <tt>com.google.code.ibaguice.core.datasource.PooledDataSourceProvider</tt> is the provider that builds the <tt>org.apache.ibatis.datasource.pooled.PooledDataSource</tt> and helps users to configure it.</p>
<p>Follows below the resume table of supported properties:</p>
<table class="bodyTable"><tbody><tr class="a"><th align="left">Property</th>
<th align="center">Required</th>
<th align="center">Bind Java Type</th>
</tr>
<tr class="b"><td align="left">JDBC.driver</td>
<td align="center">true</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="a"><td align="left">JDBC.url</td>
<td align="center">true</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="b"><td align="left">JDBC.username</td>
<td align="center">true</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="a"><td align="left">JDBC.password</td>
<td align="center">true</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="b"><td align="left">JDBC.autoCommit</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="a"><td align="left">JDBC.loginTimeout</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">JDBC.driverProperties</td>
<td align="center">false</td>
<td align="center">java.util.Properties</td>
</tr>
</tbody>
</table>
</div>
<div class="section"><h3><a name="JNDI_Data_Source_Provider">JNDI Data Source Provider</a></h3>
<p>The <tt>com.google.code.ibaguice.core.datasource.JndiDataSourceProvider</tt> is the provider that builds the <tt>org.apache.ibatis.datasource.jndi.JndiDataSourceFactory</tt> and helps users to configure it.</p>
<p>Follows below the resume table of supported properties:</p>
<table class="bodyTable"><tbody><tr class="a"><th align="left">Property</th>
<th align="center">Required</th>
<th align="center">Bind Java Type</th>
</tr>
<tr class="b"><td align="left">jndi.initialContext</td>
<td align="center">false</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="a"><td align="left">jndi.dataSource</td>
<td align="center">false</td>
<td align="center">java.lang.String</td>
</tr>
</tbody>
</table>
</div>
<div class="section"><h3>Apache DBCP Provider</h3>
<p>Users that want to use the <i>Apache DBCP</i> have to add in the <tt>pom.xml</tt> the following dependency:</p>
<div class="source"><pre>&lt;dependencies&gt;
    ...
    &lt;dependency&gt;
        &lt;groupId&gt;com.google.code.ibaguice.datasource&lt;/groupId&gt;
        &lt;artifactId&gt;ibaguice-dbcp&lt;/artifactId&gt;
        &lt;version&gt;XX.XX&lt;/version&gt;
    &lt;/dependency&gt;
    ...
&lt;/dependencies&gt;</pre>
</div>
<div class="section"><h4><a name="Basic_Data_Source_Provider">Basic Data Source Provider</a></h4>
<p>The <tt>com.google.code.ibaguice.datasource.dbcp.BasicDataSourceProvider</tt> is the provider that builds the <tt>org.apache.commons.dbcp.BasicDataSource</tt> and helps users to configure it.</p>
<p>Follows below the resume table of supported properties; for more details please consult the <a href="http://commons.apache.org/dbcp/configuration.html" class="externalLink">Official reference</a>.</p>
<table class="bodyTable"><tbody><tr class="b"><th align="left">Property</th>
<th align="center">Required</th>
<th align="center">Bind Java Type</th>
</tr>
<tr class="a"><td align="left">JDBC.driver</td>
<td align="center">true</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="b"><td align="left">JDBC.url</td>
<td align="center">true</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="a"><td align="left">JDBC.username</td>
<td align="center">true</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="b"><td align="left">JDBC.password</td>
<td align="center">true</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="a"><td align="left">JDBC.autoCommit</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="b"><td align="left">JDBC.loginTimeout</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="a"><td align="left">JDBC.driverProperties</td>
<td align="center">false</td>
<td align="center">java.util.Properties</td>
</tr>
<tr class="b"><td align="left">DBCP.accessToUnderlyingConnectionAllowed</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="a"><td align="left">DBCP.defaultCatalog</td>
<td align="center">false</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="b"><td align="left">DBCP.defaultReadOnly</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="a"><td align="left">DBCP.defaultTransactionIsolation</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">DBCP.initialSize</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="a"><td align="left">DBCP.maxActive</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">DBCP.maxIdle</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="a"><td align="left">DBCP.maxOpenPreparedStatements</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">DBCP.maxWait</td>
<td align="center">false</td>
<td align="center">long</td>
</tr>
<tr class="a"><td align="left">DBCP.minEvictableIdleTimeMillis</td>
<td align="center">false</td>
<td align="center">long</td>
</tr>
<tr class="b"><td align="left">DBCP.minIdle</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="a"><td align="left">DBCP.numTestsPerEvictionRun</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">DBCP.poolPreparedStatements</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="a"><td align="left">DBCP.testOnBorrow</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="b"><td align="left">DBCP.testOnReturn</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="a"><td align="left">DBCP.testWhileIdle</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="b"><td align="left">DBCP.validationQuery</td>
<td align="center">false</td>
<td align="center">java.lang.String</td>
</tr>
</tbody>
<caption>com.google.code.ibaguice.datasource.dbcp.BasicDataSourceProvider properties</caption>
</table>
</div>
<div class="section"><h4><a name="Shared_Pool_Data_Source">Shared Pool Data Source</a></h4>
<p>The <tt>com.google.code.ibaguice.datasource.dbcp.SharedPoolDataSourceProvider</tt> is the provider that builds the <tt>org.apache.commons.dbcp.datasources.SharedPoolDataSource</tt> and helps users to configure it.</p>
<p><b>NOTE</b> This class requires a <tt>javax.sql.ConnectionPoolDataSource</tt> existing binding in order to be instantiated.</p>
<p>Follows below the resume table of supported properties:</p>
<table class="bodyTable"><tbody><tr class="a"><th align="left">Property</th>
<th align="center">Required</th>
<th align="center">Bind Java Type</th>
</tr>
<tr class="b"><td align="left">JDBC.autoCommit</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="a"><td align="left">JDBC.loginTimeout</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">DBCP.defaultReadOnly</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="a"><td align="left">DBCP.defaultTransactionIsolation</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">DBCP.maxActive</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="a"><td align="left">DBCP.maxIdle</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">DBCP.maxWait</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="a"><td align="left">DBCP.minEvictableIdleTimeMillis</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">DBCP.numTestsPerEvictionRun</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="a"><td align="left">DBCP.testOnBorrow</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="b"><td align="left">DBCP.testOnReturn</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="a"><td align="left">DBCP.testWhileIdle</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="b"><td align="left">DBCP.validationQuery</td>
<td align="center">false</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="a"><td align="left">DBCP.name</td>
<td align="center">false</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="b"><td align="left">DBCP.jndi.key</td>
<td align="center">false</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="a"><td align="left">DBCP.jndi.value</td>
<td align="center">false</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="b"><td align="left">DBCP.rollbackAfterValidation</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="a"><td align="left">DBCP.timeBetweenEvictionRunsMillis</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">DBCP.description</td>
<td align="center">false</td>
<td align="center">java.lang.String</td>
</tr>
</tbody>
<caption>com.google.code.ibaguice.datasource.dbcp.SharedPoolDataSourceProvider properties</caption>
</table>
</div>
<div class="section"><h4><a name="Per_User_Pool_DataSource">Per User Pool DataSource</a></h4>
<p>The <tt>com.google.code.ibaguice.datasource.dbcp.PerUserPoolDataSourceProvider</tt> is the provider that builds the <tt>org.apache.commons.dbcp.datasources.PerUserPoolDataSource</tt> and helps users to configure it.</p>
<p><b>NOTE</b> This class requires a <tt>javax.sql.ConnectionPoolDataSource</tt> existing binding in order to be instantiated.</p>
<p>Follows below the resume table of supported properties:</p>
<table class="bodyTable"><tbody><tr class="a"><th align="left">Property</th>
<th align="center">Required</th>
<th align="center">Bind Java Type</th>
</tr>
<tr class="b"><td align="left">JDBC.autoCommit</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="a"><td align="left">JDBC.loginTimeout</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">DBCP.defaultReadOnly</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="a"><td align="left">DBCP.defaultTransactionIsolation</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">DBCP.minEvictableIdleTimeMillis</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="a"><td align="left">DBCP.numTestsPerEvictionRun</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">DBCP.testOnBorrow</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="a"><td align="left">DBCP.testOnReturn</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="b"><td align="left">DBCP.testWhileIdle</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="a"><td align="left">DBCP.validationQuery</td>
<td align="center">false</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="b"><td align="left">DBCP.name</td>
<td align="center">false</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="a"><td align="left">DBCP.jndi.key</td>
<td align="center">false</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="b"><td align="left">DBCP.jndi.value</td>
<td align="center">false</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="a"><td align="left">DBCP.rollbackAfterValidation</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="b"><td align="left">DBCP.timeBetweenEvictionRunsMillis</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="a"><td align="left">DBCP.maxActive</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">DBCP.maxIdle</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="a"><td align="left">DBCP.maxWait</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">DBCP.description</td>
<td align="center">false</td>
<td align="center">java.lang.String</td>
</tr>
</tbody>
<caption>com.google.code.ibaguice.datasource.dbcp.PerUserPoolDataSourceProvider properties</caption>
</table>
<p><b>Configuring 'PerUser' properties</b> since these settings can't be easily covered using <tt>com.google.inject.name.Named</tt> annotations, and we don't want to put a limit on how users can retrieve these informations, the library provides the <tt>com.google.code.ibaguice.datasource.dbcp.PerUserPoolDataSourceModule</tt> module that alleviates the task of binding 'per users' properties.</p>
<p>So, developers have to write their own <tt>com.google.inject.Provider</tt> for mapped properties and binding them through the module; keep in mind that every provider is <i>optional</i> so, if not specified, properties won't be set.</p>
<p>Let's take a look at an example that shows how to set the <tt>perUserDefaultAutoCommit</tt> properties; first of all, let's implement the provider that communicates he user bindings:</p>
<div class="source"><pre>import com.google.inject.Provider;
import com.google.inject.name.Named;

class MyPerUserDefaultAutoCommit implements Provider&lt;Map&lt;String, Boolean&gt;&gt; {

    private final Map&lt;String, Boolean&gt; perUserDefaultAutoCommitMap;

    public MyPerUserDefaultAutoCommit(@Named(&quot;perUserDefaultAutoCommit.url&quot;) URL url) {
        // reads the URL and populate a map
    }

    public Map&lt;String, Boolean&gt; get() {
        return this.perUserDefaultAutoCommitMap;
    }

}</pre>
</div>
<p>then, create the <tt>com.google.code.ibaguice.datasource.dbcp.PerUserPoolDataSourceModule</tt> and binding it:</p>
<div class="source"><pre>PerUserPoolDataSourceModule perUserPoolDataSourceModule = new PerUserPoolDataSourceModule();
perUserPoolDataSourceModule.setPerUserDefaultAutoCommitProviderClass(MyPerUserDefaultAutoCommit.class);</pre>
</div>
<p>So, finally you're ready to create the context:</p>
<div class="source"><pre>import com.google.code.ibaguice.core.SqlSessionFactoryModule;
import com.google.code.ibaguice.datasource.dbcp.PerUserPoolDataSourceModule;
import com.google.code.ibaguice.datasource.dbcp.PerUserPoolDataSourceProvider;

Injector injector = Guice.createInjector(
    new SqlSessionFactoryModule(PerUserPoolDataSourceProvider.class),
    perUserPoolDataSourceModule
);</pre>
</div>
<p>that's all :)</p>
<p><i>Note</i> it's strongly reccommended to use the same <tt>com.google.code.ibaguice.datasource.dbcp.PerUserPoolDataSourceModule</tt> to set also the other 'per user' bindings, resumed in the following table:</p>
<table class="bodyTable"><tbody><tr class="a"><th align="left">Provider Type</th>
<th align="center">to bind</th>
</tr>
<tr class="b"><td align="left">Map&lt;String, Boolean&gt;</td>
<td align="center">perUserDefaultAutoCommit</td>
</tr>
<tr class="a"><td align="left">Map&lt;String, Boolean&gt;</td>
<td align="center">perUserDefaultReadOnly</td>
</tr>
<tr class="b"><td align="left">Map&lt;String, Integer&gt;</td>
<td align="center">perUserDefaultTransactionIsolation</td>
</tr>
<tr class="a"><td align="left">Map&lt;String, Integer&gt;</td>
<td align="center">perUserMaxActive</td>
</tr>
<tr class="b"><td align="left">Map&lt;String, Integer&gt;</td>
<td align="center">perUserMaxIdle</td>
</tr>
<tr class="a"><td align="left">Map&lt;String, Integer&gt;</td>
<td align="center">perUserMaxWait</td>
</tr>
</tbody>
</table>
</div>
<div class="section"><h4><a name="Connection_Pool_Data_Source_driver_adapter">Connection Pool Data Source driver adapter</a></h4>
<p>The <tt>com.google.code.ibaguice.datasource.dbcp.DriverAdapterCPDSProvider</tt> provides the <tt>org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS</tt> adapter for jdbc drivers that do not include an implementation of <tt>javax.sql.ConnectionPoolDataSource</tt>.</p>
<p>Follows below the resume table of supported properties:</p>
<table class="bodyTable"><tbody><tr class="b"><th align="left">Property</th>
<th align="center">Required</th>
<th align="center">Bind Java Type</th>
</tr>
<tr class="a"><td align="left">JDBC.driver</td>
<td align="center">true</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="b"><td align="left">JDBC.url</td>
<td align="center">true</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="a"><td align="left">JDBC.username</td>
<td align="center">true</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="b"><td align="left">JDBC.password</td>
<td align="center">true</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="a"><td align="left">JDBC.loginTimeout</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">DBCP.maxActive</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="a"><td align="left">DBCP.maxIdle</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">DBCP.minEvictableIdleTimeMillis</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="a"><td align="left">DBCP.numTestsPerEvictionRun</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">DBCP.poolPreparedStatements</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="a"><td align="left">DBCP.timeBetweenEvictionRunsMillis</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">DBCP.maxOpenPreparedStatements</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="a"><td align="left">DBCP.description</td>
<td align="center">false</td>
<td align="center">java.lang.String</td>
</tr>
</tbody>
<caption>com.google.code.ibaguice.datasource.dbcp.DriverAdapterCPDSProvider properties</caption>
</table>
</div>
</div>
<div class="section"><h3><a name="C3P0_Provider">C3P0 Provider</a></h3>
<p>The <tt>com.google.code.ibaguice.datasource.C3p0DataSourceProvider</tt> is the provider that builds the <tt>com.mchange.v2.c3p0.ComboPooledDataSource</tt> and helps users to configure it.</p>
<p>Users that want to use the <i>C3P0</i> have to add in the <tt>pom.xml</tt> the following dependency:</p>
<div class="source"><pre>&lt;dependencies&gt;
    ...
    &lt;dependency&gt;
        &lt;groupId&gt;com.google.code.ibaguice.datasource&lt;/groupId&gt;
        &lt;artifactId&gt;ibaguice-c3p0&lt;/artifactId&gt;
        &lt;version&gt;XX.XX&lt;/version&gt;
    &lt;/dependency&gt;
    ...
&lt;/dependencies&gt;</pre>
</div>
<p>Follows below the resume table of supported properties; for more details please consult the <a href="http://www.mchange.com/projects/c3p0/index.html#configuration" class="externalLink">Official reference</a>.</p>
<table class="bodyTable"><tbody><tr class="b"><th align="left">Property</th>
<th align="center">Required</th>
<th align="center">Bind Java Type</th>
</tr>
<tr class="a"><td align="left">JDBC.driver</td>
<td align="center">true</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="b"><td align="left">JDBC.url</td>
<td align="center">true</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="a"><td align="left">JDBC.username</td>
<td align="center">true</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="b"><td align="left">JDBC.password</td>
<td align="center">true</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="a"><td align="left">JDBC.autoCommit</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="b"><td align="left">JDBC.driverProperties</td>
<td align="center">false</td>
<td align="center">java.util.Properties</td>
</tr>
<tr class="a"><td align="left">c3p0.acquireIncrement</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">c3p0.acquireRetryAttempts</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="a"><td align="left">c3p0.acquireRetryDelay</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">c3p0.automaticTestTable</td>
<td align="center">false</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="a"><td align="left">c3p0.breakAfterAcquireFailure</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="b"><td align="left">c3p0.checkoutTimeout</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="a"><td align="left">c3p0.connectionCustomizerClassName</td>
<td align="center">false</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="b"><td align="left">c3p0.connectionTesterClassName</td>
<td align="center">false</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="a"><td align="left">c3p0.idleConnectionTestPeriod</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">c3p0.initialPoolSize</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="a"><td align="left">c3p0.maxAdministrativeTaskTime</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">c3p0.maxConnectionAge</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="a"><td align="left">c3p0.maxIdleTime</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">c3p0.maxIdleTimeExcessConnections</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="a"><td align="left">c3p0.maxPoolSize</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">c3p0.maxStatements</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="a"><td align="left">c3p0.maxStatementsPerConnection</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">c3p0.minPoolSize</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="a"><td align="left">c3p0.preferredTestQuery</td>
<td align="center">false</td>
<td align="center">java.lang.String</td>
</tr>
<tr class="b"><td align="left">c3p0.propertyCycle</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="a"><td align="left">c3p0.testConnectionOnCheckin</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="b"><td align="left">c3p0.testConnectionOnCheckout</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
<tr class="a"><td align="left">c3p0.unreturnedConnectionTimeout</td>
<td align="center">false</td>
<td align="center">int</td>
</tr>
<tr class="b"><td align="left">c3p0.usesTraditionalReflectiveProxies</td>
<td align="center">false</td>
<td align="center">boolean</td>
</tr>
</tbody>
</table>
</div>
</div>

          </div>
        </div>
        <div class="clear">
          <hr/>
        </div>
        <div id="footer">
          <div class="xright">Copyright &#169;         
   
          2010.
    
      All Rights Reserved.    
  

  
    
            
  
    
  </div>
          <div class="clear">
            <hr/>
          </div>
        </div>
    </div>
  </body>
</html>
